package com.airspyar;

public class Vector3d {
        private float x, y, z;

        public Vector3d(float x, float y, float z) {
                this.x = x;
                this.y = y;
                this.z = z;
        }

        public void setX(float x) {
                this.x = x;
        }

        public void setY(float y) {
                this.y = y;
        }

        public void setZ(float z) {
                this.z = z;
        }

        public float getX() {
                return x;
        }

        public float getY() {
                return y;
        }

        public float getZ() {
                return z;
        }

        public void move(Vector3d vector3D) {
                this.x += vector3D.x;
                this.y += vector3D.y;
                this.z += vector3D.z;
        }

        public void move(float x, float y, float z) {
                this.x += x;
                this.y += y;
                this.z += z;
        }

        public float[] getCoords() {
                return (new float[] { x, y, z });
        }

        public boolean equals(Object o) {
                if (o instanceof Vector3d) {
                	Vector3d p = (Vector3d) o;
                        return p.x == x && p.y == y && p.z == z;
                }
                return false;
        }

        public int hashCode() {
                return (int) (x + y + z);
        }

        public void add(float x, float y, float z) {
                this.x += x;
                this.y += y;
                this.z += z;
        }

        public float dotProduct(Vector3d other) {
                return other.x * x + other.y * y + other.z * z;
        }

        public void normalize() {
                float magnitude = (float)Math.sqrt(dotProduct(this));
                x/=magnitude;
                y/=magnitude;
                z/=magnitude;
        }

        public float lenght(){
        	return (float)Math.sqrt(Math.pow(this.x, 2)+Math.pow(this.y, 2)+Math.pow(this.z, 2));
        }
        
        @Override
        public String toString() {
                return (new StringBuffer("[Vector3D x:")).append(x).append(" y:")
                                .append(y).append(" z:").append(z).append("]").toString();
        }

		@Override
		public Vector3d clone() {
			return new Vector3d(x,y,z);
		}
}
